//
//  BaseNavigationVC.m
//  dadashi
//
//  Created by glavesoft on 15/10/29.
//  Copyright © 2015年 jiang.123. All rights reserved.
//

#import "BaseNavigationVC.h"
//#import "YuyueDetailsViewController.h"
//#import "TimeOutParkingViewController.h"
//#import "ParkingDetailsViewController.h"
//#import "ParkingListViewController.h"
//#import "CheWeiDetailsViewController.h"
//#import "NewPayVC.h"
//#import "NaviMapViewController.h"
//#import "ShareYuyueSuccessViewController.h"
//#import "PayDingjinViewController.h"
//#import "ShareStartJifeiViewController.h"
//#import "MapYuyueTimeoutViewController.h"
//#import "SharePayMoneyViewController.h"
//#import "BandSuccessViewController.h"
//#import "BandPhoneViewController.h"
//#import "BandPasswordViewController.h"
@interface BaseNavigationVC ()

@end

@implementation BaseNavigationVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UIImageView *navBarHairlineImageView = [self findHairlineImageViewUnder:self.view];
    
    [navBarHairlineImageView setHidden:YES];
    self.interactivePopGestureRecognizer.delegate = (id)self;
    
}

- (void)back
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


//通过一个方法来找到这个黑线(findHairlineImageViewUnder):
- (UIImageView *)findHairlineImageViewUnder:(UIView *)view {
    if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
        return (UIImageView *)view;
    }
    for (UIView *subview in view.subviews) {
        UIImageView *imageView = [self findHairlineImageViewUnder:subview];
        if (imageView) {
            return imageView;
        }
    }
    return nil;
}

+ (void)initialize
{
    // 1.设置导航栏主题
    [self setupNavBarTheme];
    
    // 2.设置导航栏按钮主题
    [self setupBarButtonItemTheme];
}

/**
 *  设置导航栏按钮主题
 */
+ (void)setupBarButtonItemTheme
{
    UIBarButtonItem *item = [UIBarButtonItem appearance];
    // 设置背景
//        [item setBackgroundImage:[UIImage imageWithName:@"navigationbar_button_background"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
//        [item setBackgroundImage:[UIImage imageWithName:@"navigationbar_button_background_pushed"] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
//        [item setBackgroundImage:[UIImage imageWithName:@"navigationbar_button_background_disable"] forState:UIControlStateDisabled barMetrics:UIBarMetricsDefault];
    // 设置文字属性
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] =[UIColor whiteColor];   // textAttrs[UITextAttributeTextShadowOffset] = [NSValue valueWithUIOffset:UIOffsetZero];
  //  textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:IOS7 ? 15 : 12];
    [item setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:textAttrs forState:UIControlStateHighlighted];
    
    NSMutableDictionary *disableTextAttrs = [NSMutableDictionary dictionary];
    disableTextAttrs[NSForegroundColorAttributeName] =  [UIColor lightGrayColor];
    [item setTitleTextAttributes:disableTextAttrs forState:UIControlStateDisabled];
    
}

/**
 *  设置导航栏主题
 */
+ (void)setupNavBarTheme
{
    // 取出appearance对象
    UINavigationBar *navBar = [UINavigationBar appearance];

     //设置标题属性
    UIImage *blueImage = [self imageWithColor:[UIColor cyanColor]];
    [navBar setBackgroundImage:blueImage forBarMetrics:(UIBarMetricsDefault)];

    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
//  textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:30];
    [navBar setTitleTextAttributes:textAttrs];

}

+ (UIImage *)imageWithColor:(UIColor *)color {
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

//- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
//
//    if (self.childViewControllers.count == 1) {
//        return NO;
//    }
//    if ([self.topViewController isKindOfClass:[YuyueDetailsViewController class]])
//    {
//        return NO;
//    }
//    if ([self.topViewController isKindOfClass:[TimeOutParkingViewController class]])
//    {
//        return NO;
//    }
//    if ([self.topViewController isKindOfClass:[ParkingDetailsViewController class]])
//    {
//        return NO;
//    }
//    if ([self.topViewController isKindOfClass:[ParkingListViewController class]])
//    {
//        return NO;
//    }
//    if ([self.topViewController isKindOfClass:[CheWeiDetailsViewController class]])
//    {
//        return NO;
//    }
//    if ([self.topViewController isKindOfClass:[NewPayVC class]])
//    {
//        return NO;
//    }
//    if ([self.topViewController isKindOfClass:[NaviMapViewController class]])
//    {
//        return NO;
//    }
//    if ([self.topViewController isKindOfClass:NSClassFromString(@"ZYOldCNew1PswVC")]) {
//        return NO;
//    }
//    if ([self.topViewController isKindOfClass:NSClassFromString(@"ZYMarkCVC")]) {
//        return NO;
//    }
//    if ([self.topViewController isKindOfClass:[ShareYuyueSuccessViewController class]]) {
//        return NO;
//    }
//    if ([self.topViewController isKindOfClass:[PayDingjinViewController class]]) {
//        return NO;
//    }
//    if ([self.topViewController isKindOfClass:[ShareStartJifeiViewController class]]) {
//        return NO;
//    }
//    if ([self.topViewController isKindOfClass:[MapYuyueTimeoutViewController class]]) {
//        return NO;
//    }
//    if ([self.topViewController isKindOfClass:[SharePayMoneyViewController class]]) {
//        return NO;
//    }
//    if ([self.topViewController isKindOfClass:[BandPhoneViewController class]]) {
//        return NO;
//    }
//    if ([self.topViewController isKindOfClass:[BandSuccessViewController class]]) {
//        return NO;
//    }
//    if ([self.topViewController isKindOfClass:[BandPasswordViewController class]]) {
//        return NO;
//    }
//    return YES;
//}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return YES;
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
        
//  viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"qg_fbqg_back"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]style:UIBarButtonItemStyleDone target:self action:@selector(back)];

    }
    [super pushViewController:viewController animated:animated];
}

@end
